package com.tim.arc.groovy.base

/**运算符重载
 运算符	对应方法	示例
 +	plus()	a + b → a.plus(b)
 -	minus()	a - b → a.minus(b)
 *	multiply()	a * b → a.multiply(b)
 /	div()	a / b → a.div(b)
 %	mod()	a % b → a.mod(b)
 **	power()	a ** b → a.power(b)
 ==	equals()	a == b → a.equals(b)（注意：Groovy 也支持 compareTo 用于 == 和 <=>）
 <, <=, >, >=	compareTo()	需实现 Comparable 接口
 []	getAt(), putAt()	list[0] → list.getAt(0), list[0] = x → list.putAt(0, x)
 <<	leftShift()	stream << obj → stream.leftShift(obj)
 >>	rightShift()	a >> b → a.rightShift(b)
 &	and()	a & b → a.and(b)
 `	`	or()
 ++	next()	a++ → a.next()
 --	previous()	a-- → a.previous()
 *
 * */

class Vector{
    double x;
    double y;

    Vector(double x, double y) {
        this.x = x
        this.y = y
    }

    Vector plus(Vector other){
        return new Vector(this.x+other.x, this.y+other.y);
    }
}

Vector v1=new Vector(1,2);
def v2=new Vector(2,3);
Vector v3=v1+v2;
println(v3.x+","+v3.y)

